<?php 
$itm_cnt = 0;
$edit = 'none';
include('../../Connections/KRAPPERCON.php');
$combo = '';
include('../../Query_Min/getAlmacenes.php');
$combo_alm = $combo;
$combo_um = '';
include('../../Query_Min/getUMedidas.php');
$find = false;

$oper = getVal('oper');

if ($oper == 'view'){
$orden = getVal('orden');
$sql_oc = "call sp_getOCDet(".$orden.");";
	$res = $mysqli->query($sql_oc) or die($mysqli->error.__LINE__);

	if ($res){
		$find = true;
		while($row = $res->fetch_assoc()){
		/*
			if ($itm_cnt==0){
				$edit = '';
				$disable2 = "disabled";
			// Obtener Datos de cabecera
				$fecdoc = $row['OrdenFecDoc'];
				$feccre = $row['OrdenFecCre'];
				$userid  = $row['UserID'];
				$fecent = $row['OrdenFecEnt'];
				$ocprov = $row['ProveedID'];
				$ocref = $row['OrdenRef'];
				$ocmonto = $row['OrdenMonto'];
				$ocldoc = $row['ClaDocID'];
			}
			*/
			$itm_cnt = $itm_cnt + 1;
				$oc_posn[] = $row['OrdenPos'];
			$oc_dcto[] = $row['DetOrdDct'];
			$oc_cods[] = $row['ArticuloID'];
			$oc_noms[] = $row['DetOrdTxt'];
			$oc_prun[] = $row['DetPreUM'];
			$oc_ctdf[] = $row['DetCtdFin'];
			$oc_unm[] = $row['UniMedID'];
			//$oc_brut[] = $row[''];
						
			$oc_spid[] = $row['SolPedID'];
			$oc_spit[] = $row['SolPedItm'];
			$oc_qtpe[] = $row['DetOrdQtp'];
			$oc_qtat[] = $row['DetOrdQta'];
			$oc_nets[] = $row['DetPreNet'];
			$oc_almc[] = $row['AlmacenID'];
			//$oc_cent[] = $row['CentroID'];
			$oc_dels[] = $row['DetOrdDel'];
		}
		
		include ('OperItmOC.php');
		
		$res->close();
		$mysqli->check_result();
	}
}
elseif ($oper == 'hist') {
$orden = getVal('orden');
$posic = getVal('posic');
?>
    <table width="100%" border="1" cellspacing="0" cellpadding="0" rules="all">
<thead>
  <tr>
    <th>Tipo Operaci&oacute;n</th>
    <th>Clase</th>
    <th>Documento</th>
    <th>Monto</th>
    <th>Moneda</th>
    <th>Monto ML</th>
    <th>Cantidad</th>
    </tr>
  </thead>
  <tbody>
    <?php 
if ($orden > 0 and $posic > 0){
$tot = 0;
$totq = 0;
	$sql = "call sp_getHistDocOC('".$orden."','".$posic."');";
	$res = $mysqli->query($sql);
		if ($res){
			while($row = $res->fetch_assoc()){
?>

  <tr>
    <td><?php echo $row['operID']; ?></td>
    <td><?php echo $row['idCond']; ?></td>
    <td><a href="#" onclick="showDocOC(this);"><?php echo $row['MovimientoID']; ?></a></td>
    <td class="qt"><?php echo $row['monVal']; ?></td>
    <td><?php echo $row['moneyID'];?></td>
    <td class="qt"><?php echo $row['monPEN'];?></td>
    <td class="qt"><?php echo $row['ctdUM'];?></td>
    </tr>
<?php 				
		//$tot += $row['FactCompNeto'];
		//$totq += $row['FactCompQta']; 
			}
			$res->close();
			$mysqli->check_result();
		}
	}
?>
  </tbody>
  <tfoot>
  <tr>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
    <th class="qt">&nbsp;</th>
    <th class="qt">&nbsp;</th>
    <th class="qt">&nbsp;</th>
    </tr>
  </tfoot>
</table>
<?php 	
}
elseif ( $oper == 'provision'){
	$newnro = $_POST['orden'];
	$arr = array();
	$sql = "call sp_getProvisionOC('".$newnro."')";
	$res = $mysqli->query($sql);
	if ($res){
		while($row=$res->fetch_assoc()){
		$fila = new Any;
		$fila->cod = $row['idCond'];
		$fila->imp = $row['valCond'];
		$fila->mon = $row['monCond'];
		$fila->pen = $row['valPEN'];						
		$fila->del = $row['indDel'];
		$fila->use = $row['useChk'];				
		$arr[] = $fila;
		}
		echo (json_encode($arr));
	$res->close();
	$mysqli->check_result();
	}
}
?>
